<?php
	require_once('../utils/query.php');
	require_once('../utils/logged_in.php');

	$tradeID = $_POST["tradeID"];
	$person = $_POST["person"]; // Taken from tradeHome.php  $.post by the function yourCards() which calls loadPersonCards


	if($person=="notme")
	{
		$rez = execute_query("SELECT userid1, userid2 FROM Trade where tradeid='%s'", $tradeID); // Will return the row and userid1 column and the userid2 column
		$rez = mysql_fetch_array($rez);
		if($rez[0]==$drupaluid) 
		{
			$person = $rez[1];  
		}
		else
		{
			$person = $rez[0];
		}
	}
	
?>

<!--<ul class="cards">-->
<ul>
	<?php


		if($tradeID)
		{		
			$tradeCards = execute_query("SELECT possessionid FROM TradePossession WHERE tradeid='%s'", $tradeID);
		}
		else
		{
			$tradeCards = execute_query("SELECT possessionid FROM Possession WHERE userid='%s'", $drupaluid);
		}
		


		while ($row = mysql_fetch_array($tradeCards))
		{
			$cardID = execute_query("SELECT cardid FROM Possession WHERE possessionid='%s' AND userid='%s'", $row[0], $person);
			$cardID = mysql_result($cardID, 0);
			
			$cards_result = execute_query("SELECT name, card_img, type FROM cards_lu WHERE front is null AND full_id='%s'", $cardID);
			$row2 = mysql_fetch_array($cards_result);
			$name = $row2[0];
			$card_img = $row2[1];
			$type = $row2[2];
			
			$color = "#ffffff";

			if ($type == 1)
				$color = "#dc3122";
			else if ($type == 2)
				$color = "#ddd327";
			else if ($type == 3)
				$color = "#0145f3";
			else if ($type == 10)
				$color = "#653b67";
				
		
			if(strlen($name) > 16)
			$showname = substr ($name,0,16) . "...";
			else
			$showname = $name;

			if($cardID!="")
			{
	?>
			
			<li class="card" id="<?php echo($cardID); ?>">
				<div class="cardImg">
					<img src="../../../card_imgs/<?php echo($card_img); ?>">
				</div>
				<!--<div class="cardDesc" style="background:<?php echo($color); ?>;">-->
				<div class="cardDesc">
					<?php echo($showname); ?>
				</div>
			</li>
	<?php
			}
		}
		
	?>
</ul>